(function() {
    var F = TED.extend, C = TED.EventDispatcher, B = TED.EditorPlugins.Refer;
    function E(G) {
        E.superclass.call(this);
        this.init(G || {})
    }
    E.defaultConfig = {height: "200px",width: "400px",maxHeight: null,autoFocus: true,autoEnable: true,autoHeight: false,editAreaClassName: "tb-editor-editarea",editAreaWrapperClassName: "tb-editor-editarea-wrapper",wrapperClassName: "tb-editor-wrapper",disabledEditAreaClassName: "tb-editor-editarea disabled",disabledWrapperClassName: "tb-editor-wrapper disabled",imageClassName: "BDE_Image",smileyClassName: "BDE_Smiley",emptyClassName: "BDE_Empty",musicClassName: "BDE_Music",didaDelay: 300,imageWidthLimit: 560};
    E.ResizeImage = function(H) {
        H.removeAttribute("onload");
        H.removeAttribute("onerror");
        if (H.width > E.defaultConfig.imageWidthLimit) {
            var I = H.width;
            var G = H.height;
            H.setAttribute("width", E.defaultConfig.imageWidthLimit);
            H.setAttribute("height", E.defaultConfig.imageWidthLimit * G / I);
            H.setAttribute("changedsize", true)
        }
    };
    F(E, C, {config: null,enabled: false,focused: false,autoHeighted: false,wrapper: null,editArea: null,container: null,id: null,editValidHTML: ["br", "embed"],submitValidHTML: ["br", "embed"],execCommand: function(K, J) {
            if (!this.enabled) {
                return false
            }
            if (!this.focused) {
                this.focus()
            }
            var H = true, K = K.toLowerCase(), M;
            if (typeof this["cmd_" + K] === "function") {
                var G = [];
                for (var I = 1; I < arguments.length; I++) {
                    G.push(arguments[I])
                }
                M = this["cmd_" + K].apply(this, G);
                H = M[0];
                if (M[1]) {
                    K = M[1]
                }
                if (M[2]) {
                    J = M[2]
                }
            }
            if (H) {
                try {
                    document.execCommand(K, false, J)
                } catch (L) {
                    throw new Error("执行action时，发生异常：" + L.message)
                }
            }
            if (!this.ua.ie) {
                this.saveRange()
            }
        },getImageNum: function() {
            return this.getTagNum("img", this.config.imageClassName)
        },getSmileyNum: function() {
            return this.getTagNum("img", this.config.smileyClassName)
        },getHtml: function() {
            this.fireEvent("gethtml");
            return this.filteSubmitHTML()
        },setHtml: function(G) {
            this.editArea.innerHTML = G
        },enable: function() {
            if (!this.enabled) {
                this.attachEvents();
                this.editArea.style.display = "none";
                this.editArea.contentEditable = true;
                this.editArea.style.display = "block";
                if (this.ua.gecko && this.editArea.innerHTML === "") {
                    this.editArea.innerHTML = "<br>"
                }
                this.editArea.className = this.config.editAreaClassName;
                this.wrapper.className = this.config.wrapperClassName;
                if (this.config.autoFocus) {
                    this.focus()
                }
                this.enabled = true
            } else {
                if (this.config.autoFocus && !this.focused) {
                    this.focus()
                }
            }
        },disable: function() {
            if (!this.enabled) {
                return
            }
            if (this.focused) {
                this.blur()
            }
            this.detachEvents();
            this.editArea.contentEditable = false;
            this.wrapper.className = this.config.disabledWrapperClassName;
            this.editArea.className = this.config.disabledEditAreaClassName;
            this.enabled = false
        },focus: function() {
            this.editArea.focus();
            if (this.ua.webkit) {
                this.resumeRange()
            }
        },blur: function() {
            if (!this.ua.ie) {
                this.saveRange()
            }
            this.editArea.blur()
        },isEmpty: function() {
            return this.isEmptyContent(this.editArea.innerHTML)
        },enableAutoHeight: function(H) {
            if (H && H <= parseInt(this.config.height)) {
                if (this.autoHeighted) {
                    this.disableAutoHeight()
                }
                return
            }
            H = H || this.config.maxHeight;
            if (this.ua.ie > 0 && this.ua.ie <= 6) {
                var G = parseInt(this.config.height), I;
                if (H) {
                    I = "this.scrollHeight <= " + G + ' ? "' + G + 'px" : (this.scrollHeight >= ' + H + ' ? "' + H + 'px" : "auto")'
                } else {
                    I = "this.scrollHeight <= " + G + ' ? "' + G + 'px" : "auto"'
                }
                this.editArea.style.setExpression("height", I)
            } else {
                this.editArea.style.minHeight = this.config.height;
                this.editArea.style.height = "auto";
                if (H) {
                    this.editArea.style.maxHeight = H + "px"
                }
            }
            this.autoHeighted = true
        },disableAutoHeight: function() {
            if (this.ua.ie > 0 && this.ua.ie <= 6) {
                this.editArea.style.removeExpression("height")
            }
            this.editArea.style.height = this.config.height;
            this.autoHeighted = false
        },empty: function() {
            this.editArea.innerHTML = ""
        },ua: function() {
            var J = function(N) {
                var O = 0;
                return parseFloat(N.replace(/\./g, function() {
                    return (O++ == 1) ? "" : "."
                }))
            }, M = navigator, L = {ie: 0,opera: 0,gecko: 0,webkit: 0,mobile: null,air: 0,caja: M.cajaVersion,secure: false,os: null}, I = navigator && navigator.userAgent, K = window && window.location, H = K && K.href, G;
            L.secure = H && (H.toLowerCase().indexOf("https") === 0);
            if (I) {
                if ((/windows|win32/i).test(I)) {
                    L.os = "windows"
                } else {
                    if ((/macintosh/i).test(I)) {
                        L.os = "macintosh"
                    }
                }
                if ((/KHTML/).test(I)) {
                    L.webkit = 1
                }
                G = I.match(/AppleWebKit\/([^\s]*)/);
                if (G && G[1]) {
                    L.webkit = J(G[1]);
                    if (/ Mobile\//.test(I)) {
                        L.mobile = "Apple"
                    } else {
                        G = I.match(/NokiaN[^\/]*/);
                        if (G) {
                            L.mobile = G[0]
                        }
                    }
                    G = I.match(/AdobeAIR\/([^\s]*)/);
                    if (G) {
                        L.air = G[0]
                    }
                }
                if (!L.webkit) {
                    G = I.match(/Opera[\s\/]([^\s]*)/);
                    if (G && G[1]) {
                        L.opera = J(G[1]);
                        G = I.match(/Opera Mini[^;]*/);
                        if (G) {
                            L.mobile = G[0]
                        }
                    } else {
                        G = I.match(/MSIE\s([^;]*)/);
                        if (G && G[1]) {
                            L.ie = J(G[1])
                        } else {
                            G = I.match(/Gecko\/([^\s]*)/);
                            if (G) {
                                L.gecko = 1;
                                G = I.match(/rv:([^\s\)]*)/);
                                if (G && G[1]) {
                                    L.gecko = J(G[1])
                                }
                            }
                        }
                    }
                }
            }
            return L
        }(),isUCWeb: function() {
            var G = navigator.userAgent.toString();
            if (G.indexOf("X11;") > -1 && G.indexOf("Linux i686;") > -1 && G.indexOf("Gecko") > -1 && G.indexOf("Firefox") < 0 && G.indexOf("Opera") < 0) {
                return true
            }
            return false
        },isAndroidOS: function() {
            var G = navigator.userAgent.toString();
            if (G.match(/android/i) != null) {
                return true
            }
            return false
        },isEmptyContent: function(G) {
            if (!G) {
                return true
            }
            return ("" === G.replace(/<br[^>]*>/gi, "").replace(/<\/?(?:span|a)[^>]*>/gi, "").replace(/[\u3000\s]+/g, "").replace(/&nbsp;/g, ""))
        },init: function(G) {
            this.augmentObject(G, this.constructor.defaultConfig || {});
            this.config = G;
            if (this.constructor.registerInstance) {
                this.id = this.constructor.registerInstance(this, G.id)
            }
            this.initComponents(G);
            this.appendToDom();
            this.initEvents();
            this.initConfig(G)
        },initComponents: function(G) {
            if (G.container) {
                if (typeof G.container === "string") {
                    this.container = document.getElementById(G.container)
                } else {
                    if (typeof G.container === "object" && G.container.nodeType === 1) {
                        this.container = G.container
                    }
                }
            }
            this.container = this.container || document.body;
            this.editArea = document.createElement("div");
            this.editArea.className = G.disabledEditAreaClassName;
            this.wrapper = document.createElement("div");
            this.wrapper.className = G.disabledWrapperClassName;
            this.editAreaWrapper = document.createElement("div");
            this.editAreaWrapper.className = G.editAreaWrapperClassName;
            this.editArea.style.height = G.height;
            this.wrapper.style.width = G.width
        },appendToDom: function() {
            this.editAreaWrapper.appendChild(this.editArea);
            this.wrapper.appendChild(this.editAreaWrapper);
            this.container.appendChild(this.wrapper)
        },initConfig: function(G) {
            if (G.autoHeight) {
                this.enableAutoHeight()
            }
            if (G.enableRefer) {
                this.addPlugin("refer", new B({uid: this.config.uid}))
            }
            if (G.autoEnable) {
                var H = this;
                setTimeout(function() {
                    H.enable();
                    H.fireEvent("initcomplete")
                }, 10)
            } else {
                this.fireEvent("initcomplete")
            }
        },initEvents: function() {
            var G = this;
            this.bindMousedown = function() {
                G.onMousedown.apply(G, arguments)
            };
            this.bindMouseup = function() {
                G.onMouseup.apply(G, arguments)
            };
            this.bindClick = function() {
                G.onClick.apply(G, arguments)
            };
            this.bindDoubleclick = function() {
                G.onDoubleclick.apply(G, arguments)
            };
            this.bindKeydown = function() {
                G.onKeydown.apply(G, arguments)
            };
            this.bindKeyup = function() {
                G.onKeyup.apply(G, arguments)
            };
            this.bindKeypress = function() {
                G.onKeypress.apply(G, arguments)
            };
            this.bindPaste = function() {
                G.onPaste.apply(G, arguments)
            };
            this.bindBlur = function() {
                G.onBlur.apply(G, arguments)
            };
            this.bindFocus = function() {
                G.onFocus.apply(G, arguments)
            }
        },attachEvents: function() {
            var G = this.editArea;
            if (!this.ua.ie) {
                G.addEventListener("mousedown", this.bindMousedown, false);
                G.addEventListener("mouseup", this.bindMouseup, false);
                G.addEventListener("click", this.bindClick, false);
                G.addEventListener("dblclick", this.bindDoubleclick, false);
                G.addEventListener("keypress", this.bindKeypress, false);
                G.addEventListener("keyup", this.bindKeyup, false);
                G.addEventListener("keydown", this.bindKeydown, false);
                G.addEventListener("paste", this.bindPaste, false);
                G.addEventListener("blur", this.bindBlur, false);
                G.addEventListener("focus", this.bindFocus, false)
            } else {
                G.attachEvent("onmousedown", this.bindMousedown);
                G.attachEvent("onmouseup", this.bindMouseup);
                G.attachEvent("onclick", this.bindClick);
                G.attachEvent("ondblclick", this.bindDoubleclick);
                G.attachEvent("onkeypress", this.bindKeypress);
                G.attachEvent("onkeyup", this.bindKeyup);
                G.attachEvent("onkeydown", this.bindKeydown);
                G.attachEvent("onpaste", this.bindPaste);
                G.attachEvent("onbeforedeactivate", this.bindBlur);
                G.attachEvent("onbeforeactivate", this.bindFocus)
            }
            this.on("dida", this.onDida, this)
        },detachEvents: function() {
            var G = this.editArea;
            if (!this.ua.ie) {
                G.removeEventListener("mousedown", this.bindMousedown, false);
                G.removeEventListener("mouseup", this.bindMouseup, false);
                G.removeEventListener("click", this.bindClick, false);
                G.removeEventListener("dblclick", this.bindDoubleclick, false);
                G.removeEventListener("keypress", this.bindKeypress, false);
                G.removeEventListener("keyup", this.bindKeyup, false);
                G.removeEventListener("keydown", this.bindKeydown, false);
                G.removeEventListener("paste", this.bindPaste, false);
                G.removeEventListener("blur", this.bindBlur, false);
                G.removeEventListener("focus", this.bindFocus, false)
            } else {
                G.detachEvent("onmousedown", this.bindMousedown);
                G.detachEvent("onmouseup", this.bindMouseup);
                G.detachEvent("onclick", this.bindClick);
                G.detachEvent("ondblclick", this.bindDoubleclick);
                G.detachEvent("onkeypress", this.bindKeypress);
                G.detachEvent("onkeyup", this.bindKeyup);
                G.detachEvent("onkeydown", this.bindKeydown);
                G.detachEvent("onpaste", this.bindPaste);
                G.detachEvent("onbeforedeactivate", this.bindBlur);
                G.detachEvent("onbeforeactivate", this.bindFocus)
            }
            this.remove("dida", this.onDida)
        },onMousedown: function(G) {
            this.fireEvent("mousedown", null, [G]);
            if (G.exitFunction) {
                return
            }
        },onMouseup: function(G) {
            this.fireEvent("mouseup", null, [G]);
            if (G.exitFunction) {
                return
            }
            if (!this.ua.ie) {
                this.saveRange()
            }
        },onClick: function(G) {
            this.fireEvent("click", null, [G]);
            if (G.exitFunction) {
                return
            }
        },onDoubleclick: function(G) {
            this.fireEvent("doubleclick", null, [G]);
            if (G.exitFunction) {
                return
            }
        },onKeydown: function(H) {
            this.fireEvent("keydown", null, [H]);
            if (H.exitFunction) {
                return
            }
            if (H.keyCode === 8) {
                if (this.ua.ie) {
                    var G = this.getRange();
                    if (G.item) {
                        G.item(0).outerHTML = "";
                        H.returnValue = false
                    }
                }
            }
        },onKeypress: function(I) {
            this.fireEvent("keypress", null, [I]);
            if (I.exitFunction) {
                return
            }
            var G = I.keyCode;
            switch (G) {
                case 13:
                    if (this.ua.ie) {
                        var H = this.getRange();
                        if (H) {
                            H.pasteHTML("<br>");
                            H.collapse(false);
                            H.select()
                        }
                        I.returnValue = false
                    } else {
                        if (this.ua.webkit) {
                            document.execCommand("insertlinebreak");
                            I.preventDefault()
                        }
                    }
                    break
            }
        },onKeyup: function(G) {
            this.fireEvent("keyup", null, [G]);
            if (G.exitFunction) {
                return
            }
            if (!this.ua.ie) {
                this.saveRange()
            }
        },onPaste: function(H) {
            this.fireEvent("paste", null, [H]);
            if (H.exitFunction) {
                return
            }
            if (this.ua.ie) {
                this.doPasteIE(H);
                this.fireEvent("afterpaste", null, [H])
            } else {
                var G = this;
                setTimeout(function() {
                    G.doPaste();
                    G.fireEvent("afterpaste", null, [H])
                }, 5)
            }
        },didaTimer: null,savedHeight: null,startDida: function() {
            var G = this;
            this.didaTimer = setInterval(function() {
                G.fireEvent("dida")
            }, this.config.didaDelay)
        },stopDida: function() {
            clearInterval(this.didaTimer)
        },onDida: function() {
            if (this.autoHeighted) {
                if (this.savedHeight === null) {
                    this.savedHeight = this.wrapper.scrollHeight;
                    return
                }
                var G = this.wrapper.scrollHeight;
                if (this.savedHeight && G !== this.savedHeight) {
                    this.fireEvent("heightChanged", null, [G, G - this.savedHeight]);
                    this.savedHeight = G
                }
            }
        },onBlur: function(G) {
            this.stopDida();
            this.focused = false;
            this.fireEvent("blur", null, [G]);
            if (G.exitFunction) {
                return
            }
            if (this.ua.ie) {
                this.saveRange()
            }
        },onFocus: function(G) {
            this.startDida();
            this.focused = true;
            this.fireEvent("focus", null, [G]);
            if (G.exitFunction) {
                return
            }
            this.resumeRange()
        },augmentObject: function(I, H) {
            for (var G in H) {
                if (H.hasOwnProperty(G)) {
                    I[G] = I[G] !== undefined ? I[G] : H[G]
                }
            }
        },getSelection: function() {
            return window.getSelection ? window.getSelection() : document.selection
        },getRange: function() {
            return this.ua.ie ? document.selection.createRange() : window.getSelection().getRangeAt(0)
        },createRange: function() {
            return this.ua.ie ? document.body.createTextRange() : document.createRange()
        },getSelectedElement: function() {
            var G = this.getRange();
            if (this.ua.ie) {
                return G.item ? G.item(0) : G.parentElement()
            }
            var H = G.commonAncestorContainer;
            if (H.nodeType === 3) {
                H = H.parentNode
            }
            return H
        },doPasteIE: function(G) {
            var H = clipboardData.getData("Text");
            if ((!H) || H == "") {
                return true
            }
            H = H.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\r?\n/g, "<br>").replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;").replace(/\s/g, "&nbsp;").replace(/\u3000/g, "&nbsp;&nbsp;");
            this.execCommand("inserthtml", H);
            G.returnValue = false
        },doPaste: function() {
            this.saveCursor();
            this.editArea.innerHTML = this.filteEditHTML();
            this.ensureCursor()
        },filteEditHTML: function() {
            return html = this.editArea.innerHTML.replace(/_moz_dirty=""/gi, "").replace(/\[/g, "[[-").replace(/\]/g, "-]]").replace(/<\/ ?tr[^>]*>/gi, "[br]").replace(/<\/ ?td[^>]*>/gi, "&nbsp;&nbsp;").replace(/<(ul|dl|ol)[^>]*>/gi, "[br]").replace(/<(li|dd)[^>]*>/gi, "[br]").replace(/<p [^>]*>/gi, "[br]").replace(new RegExp("<(/?(?:" + this.editValidHTML.join("|") + ")[^>]*)>", "gi"), "[$1]").replace(new RegExp('<span([^>]*class="?at"?[^>]*)>', "gi"), "[span$1]").replace(new RegExp('<img([^>]*class="?(?:' + this.config.imageClassName + "|" + this.config.emptyClassName + "|" + this.config.smileyClassName + "|" + this.config.flashClassName + "|" + this.config.musicClassName + ')"?[^>]*)>', "gi"), "[img$1]").replace(/<[^>]*>/g, "").replace(/\[\[\-/g, "[").replace(/\-\]\]/g, "]").replace(new RegExp("\\[(/?(?:" + this.editValidHTML.join("|") + "|img|span)[^\\]]*)\\]", "gi"), "<$1>").replace(/\r?\n/gi, "<br>")
        },filteSubmitHTML: function() {
            this.reLayout();
            var H = this.editArea.innerHTML.replace(/_moz_dirty=""/gi, "").replace(/\[/g, "[[-").replace(/\]/g, "-]]").replace(new RegExp("<(/?(?:" + this.submitValidHTML.join("|") + ")[^>]*)>", "gi"), "[$1]").replace(new RegExp('<img([^>]*class="?(?:' + this.config.imageClassName + "|" + this.config.smileyClassName + "|" + this.config.flashClassName + "|" + this.config.musicClassName + ')"?[^>]*)>', "gi"), "[img$1]").replace(/<[^>]*>/g, "").replace(/\[\[\-/g, "[").replace(/\-\]\]/g, "]").replace(new RegExp("\\[(/?(?:" + this.submitValidHTML.join("|") + "|img)[^\\]]*)\\]", "gi"), "<$1>");
            var G = document.createElement("div");
            G.innerHTML = H;
            this.parseURL(G);
            return G.innerHTML
        },filteHTML: function(H, G) {
            return H.replace(/_moz_dirty=""/gi, "").replace(/\[/g, "[[-").replace(/\]/g, "-]]").replace(new RegExp("<(/?(?:" + G.join("|") + ")[^>]*)>", "gi"), "[$1]").replace(/<[^>]*>/g, "").replace(/\[\[\-/g, "[").replace(/\-\]\]/g, "]").replace(new RegExp("\\[(/?(?:" + G.join("|") + ")[^\\]]*)\\]", "gi"), "<$1>")
        },selectNodeContents: function(H, J) {
            if (!H) {
                return
            }
            var G, I;
            if (this.ua.ie) {
                G = document.body.createTextRange();
                G.moveToElementText(H);
                if (J) {
                    G.collapse(false)
                }
                G.select()
            } else {
                I = this.getSelection();
                G = document.createRange();
                G.selectNodeContents(H);
                I.removeAllRanges();
                I.addRange(G);
                if (J) {
                    I.collapseToEnd()
                }
            }
        },hasSelection: function() {
            var G = this.getSelection();
            if (this.ua.ie) {
                return G.type.toLowerCase() !== "none"
            } else {
                if (this.ua.opera) {
                    var H = this.getRange();
                    return !(G.isCollapsed && H.startContainer && H.startContainer === H.endContainer && H.startOffset === H.endOffset)
                } else {
                    return !G.isCollapsed
                }
            }
        },saveCursor: function() {
            if (!this.focused) {
                return
            }
            var G = document.getElementById("editor-tmp-img");
            if (G) {
                G.parentNode.removeChild(G)
            }
            this.execCommand("inserthtml", '<img class="' + this.config.emptyClassName + '" id="editor-tmp-img" style="width:1px;height:1px">')
        },ensureCursor: function() {
            if (!this.focused) {
                this.focus()
            }
            var H = document.getElementById("editor-tmp-img");
            if (H) {
                if (this.ua.ie) {
                    this.selectNodeContents(H);
                    this.execCommand("delete")
                } else {
                    var G = document.createRange();
                    G.selectNode(H);
                    var I = window.getSelection();
                    I.removeAllRanges();
                    I.addRange(G);
                    this.execCommand("delete")
                }
            }
        },savedRange: null,saveRange: function() {
            this.savedRange = this.getRange()
        },resumeRange: function(G) {
            G = G || this.savedRange;
            if (!G) {
                return false
            }
            if (this.ua.ie) {
                try {
                    G.select()
                } catch (I) {
                }
            } else {
                var H = this.getSelection();
                H.removeAllRanges();
                H.addRange(G)
            }
        },cmd_inserthtml: function(G) {
            if (this.ua.ie) {
                var H = this.getRange();
                if (H.item) {
                    H.item(0).outerHTML = G
                } else {
                    H.pasteHTML(G)
                }
                return [false]
            }
            return [true]
        },insertImage: function(J, N, L, M) {
            var I = "";
            if (typeof M !== "undefined") {
                I = M
            }
            if (this.ua.ie === 8) {
                this.execCommand("inserthtml", '<img onload="TED.EditorCore.ResizeImage(this);" pic_type="' + I + '"  class="' + N + '" id="editor-tmp-img" src="' + J + '">');
                var H = document.getElementById("editor-tmp-img");
                H.removeAttribute("id");
                if (H.parentNode.lastChild === H) {
                    var K = document.createElement("br");
                    H.parentNode.appendChild(K);
                    var G = document.body.createTextRange();
                    G.moveToElementText(K);
                    if (L) {
                        G.collapse(false)
                    } else {
                        G.collapse(true)
                    }
                    G.select()
                } else {
                    if (L) {
                        this.execCommand("insertlinebreak")
                    }
                }
            } else {
                this.execCommand("inserthtml", '<img onload="TED.EditorCore.ResizeImage(this);"  pic_type="' + I + '" class="' + N + '" src="' + J + '">');
                if (L) {
                    this.execCommand("insertlinebreak")
                }
            }
        },cmd_insertlinebreak: function() {
            if (this.ua.webkit) {
                document.execCommand("insertlinebreak", false, null)
            } else {
                if (this.ua.gecko) {
                    document.execCommand("inserthtml", false, '<br id="editor-tmp-br">');
                    var H = document.getElementById("editor-tmp-br");
                    H.removeAttribute("id");
                    if (H.parentNode.lastChild === H) {
                        H.parentNode.removeChild(H);
                        document.execCommand("inserthtml", false, '<br><br id="editor-tmp-br">');
                        H = document.getElementById("editor-tmp-br");
                        H.removeAttribute("id");
                        var I = window.getSelection();
                        var J = document.createRange();
                        J.setStartBefore(H);
                        J.setEndBefore(H);
                        I.removeAllRanges();
                        I.addRange(J)
                    }
                } else {
                    if (this.ua.ie) {
                        var G = this.getRange();
                        if (G) {
                            G.pasteHTML("<br>");
                            G.collapse(false);
                            G.select()
                        }
                    }
                }
            }
            return [false]
        },cmd_insertsmiley: function(G) {
            this.insertImage(G, this.config.smileyClassName);
            return [false]
        },cmd_insertimage: function(H, J) {
            if (typeof H == "string") {
                this.insertImage(H, this.config.imageClassName, true, J)
            } else {
                if (Object.prototype.toString.apply(H) === "[object Array]") {
                    for (var I = 0, G = H.length; I < G; I++) {
                        this.insertImage(H[I], this.config.imageClassName, true, J)
                    }
                }
            }
            return [false]
        },cmd_focus2end: function() {
            var G = this.editArea;
            if (this.ua.ie) {
                G.innerHTML = G.innerHTML
            } else {
                if (G.lastChild) {
                    var I = document.createRange(), H = window.getSelection();
                    I.setStartAfter(G.lastChild);
                    I.setEndAfter(G.lastChild);
                    H.removeAllRanges();
                    H.addRange(I)
                } else {
                    G.focus()
                }
            }
            return [false]
        },editorPlugins: null,addPlugin: function(H, G) {
            G.init(this);
            this.editorPlugins = this.editorPlugins || {};
            this.editorPlugins[H] = G
        },augmentObject: function(I, H) {
            for (var G in H) {
                if (H.hasOwnProperty(G)) {
                    I[G] = I[G] !== undefined ? I[G] : H[G]
                }
            }
        },setStatsRequest: function(H) {
            var G = new Image();
            window["bd_pv_" + (new Date).getTime()] = G;
            G.src = "http://static.tieba.baidu.com/tb/img/pv.gif?fr=tb0_forum&st_mod=frspb&st_type=editor&st_value=" + H + "&t=" + (new Date).getTime();
            G = null
        },getTagNum: function(J, K) {
            var H = this.editArea.getElementsByTagName(J), L = H.length;
            if (K) {
                L = 0;
                for (var I = 0, G = H.length; I < G; I++) {
                    if (H[I].className === K) {
                        L++
                    }
                }
            }
            return L
        },reLayout: function() {
            var K = this.editArea.getElementsByTagName("img"), G = this.config.imageWidthLimit;
            var J = [];
            for (var I = 0, H = K.length; I < H; I++) {
                img = K[I];
                if (img.width === 0 || img.height === 0) {
                    J.push(img);
                    continue
                }
                if (img.className === this.config.imageClassName) {
                    if (img.width > G) {
                        img.setAttribute("width", G);
                        img.setAttribute("changedsize", true)
                    } else {
                        img.setAttribute("width", img.width)
                    }
                    img.setAttribute("height", img.height)
                } else {
                    if (img.className === this.config.smileyClassName) {
                        if (img.width > 100) {
                            img.setAttribute("width", 100)
                        } else {
                            img.setAttribute("width", img.width)
                        }
                        img.setAttribute("height", img.height)
                    } else {
                        img.setAttribute("width", img.width);
                        img.setAttribute("height", img.height)
                    }
                }
                img.removeAttribute("onload")
            }
            for (var I = 0, H = J.length; I < H; I++) {
                J[I].parentNode.removeChild(J[I])
            }
        },parseURL: function(K) {
            var H = "(=*+)", G = "(+*=)";
            var J = 4;
            var I = function(L) {
                if (L.nodeType == 3) {
                    var M = L.nodeValue;
                    if (M && M.length > J) {
                        M = "." + M;
                        M = M.replace(/([^0-9a-zA-Z])((www\.|http:\/\/|mms:\/\/|rtsp:\/\/|ftp:\/\/|https:\/\/)[0-9a-zA-Z\.\!\~\#\?\:\/\&\%\-\+\*\'\=\@\_\$]+)/gi, "$1" + H + 'a href="$2" target="_blank"' + G + "$2" + H + "/a" + G);
                        M = M.substring(1);
                        L.nodeValue = M
                    }
                } else {
                    if (L.nodeType == 1) {
                        var N = L.firstChild;
                        while (N) {
                            if (N.nodeName.toUpperCase() != "A") {
                                I(N)
                            }
                            N = N.nextSibling
                        }
                    }
                }
            };
            I(K);
            K.innerHTML = K.innerHTML.replace(/\(\=\*\+\)a\ href="www\./gi, '<a href="http://www.').replace(/\(\=\*\+\)/gi, "<").replace(/\(\+\*\=\)/gi, ">")
        }});
    window.TED["EditorCore"] = E;
    var A = {instanceNum: 0,idPrefix: "tb-editor-",registerInstance: function(G, H) {
            this.instances = this.instances || {};
            H = H || this.generateID();
            this.instances[H] = G;
            return H
        },generateID: function() {
            return this.idPrefix + ++this.instanceNum
        },getInstanceById: function(G) {
            return (G && this.instances) ? this.instances[G] : null
        }};
    window.TED["EditorInstanceManager"] = A;
    function D(G) {
        D.superclass.call(this);
        this.area = document.createElement("textarea");
        this.area.style.width = G.width;
        this.area.style.height = G.height;
        if (G.autoEnable === false) {
            this.area.disabled = true
        }
        document.getElementById(G.container).appendChild(this.area);
        this.init()
    }
    F(D, C, {isMobile: true,init: function() {
            var G = this;
            this.area.onfocus = function() {
                G.fireEvent("focus")
            };
            this.area.onclick = function() {
                G.fireEvent("click")
            };
            if (this.constructor.registerInstance) {
                this.id = this.constructor.registerInstance(this)
            }
        },getImageNum: function() {
            return 0
        },getSmileyNum: function() {
            return 0
        },getFlashNum: function() {
            return 0
        },getMusicNum: function() {
            return 0
        },getHtml: function() {
            return this.area.value.replace(/&/gi, "&amp;").replace(/</gi, "&lt;").replace(/>/gi, "&gt;").replace(/\r?\n/gi, "<br>").replace(/[\u3000\s]/gi, "&nbsp;").replace(/\t/gi, "&nbsp;&nbsp;&nbsp;&nbsp;")
        },focus: function() {
            this.area.focus()
        },isEmpty: function() {
            var G = this.area;
            return !(G && G.value && G.value.replace(/[\u3000\s]/gi, "").replace(/\r?\n/gi, "").replace(/\t/gi, "") != "")
        },quoteContainer: null,quote: function(J, G, K) {
            J = parseInt(J);
            if (J > 1) {
                if (this.quoteContainer === null) {
                    this.quoteContainer = document.createElement("div");
                    this.quoteContainer.className = "editor-quote";
                    this.area.parentNode.insertBefore(this.quoteContainer, this.area)
                }
                var I = document.getElementById("post_content_" + G).innerHTML.replace(/<img[^>]*>/gi, "[图片]").replace(/<embed[^>]*>/gi, "[视频]").replace(/<br[^>]*>/gi, " ").replace(/<a[^>]*>/gi, "").replace(/<\/a>/gi, "").subByte(270);
                this.quoteContainer.innerHTML = '<blockquote class="quote quote_simple"><a href="javascript:void(0);" onmousedown="return false;" onclick="TED.TextInput.getInstanceById(\'' + this.id + '\').unQuote();Stats.sendRequest(\'fr=tb0_forum&st_mod=pb&st_type=quote&st_value=delete\');" class="close" title="删除引用">╳</a><p class="quote_title">引用&nbsp;' + K + '&nbsp;(<a href="#' + G + '">' + J + '楼</a>)</p><p class="quote_content">' + I + "</p></blockquote>";
                this.quoteContainer.style.display = "block";
                this.fireEvent("quote", null, [G])
            } else {
                this.unQuote();
                Stats.sendRequest("fr=tb0_forum&st_mod=pb&st_type=quote&st_value=replyfirst")
            }
            var H = this;
            setTimeout(function() {
                H.focus()
            }, 100)
        },unQuote: function() {
            if (this.quoteContainer) {
                this.quoteContainer.style.display = "none"
            }
            this.fireEvent("unquote")
        }});
    TED.augmentObject(D, A);
    window.TED["TextInput"] = D
})();